package com.yuanqi.java.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanqi.java.dto.PurchaseReturnDetailQueryDTO;
import com.yuanqi.java.dto.PurchaseReturnDetailVO;
import com.yuanqi.java.result.Result;
import com.yuanqi.java.service.IPurchaseReturnDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/purchase-return-detail")
public class PurchaseReturnDetailController {

    @Autowired
    private IPurchaseReturnDetailService purchaseReturnDetailService;

    @GetMapping("/page")
    public Result<Map<String, Object>> page(@RequestParam(defaultValue = "1") long current,
                                            @RequestParam(defaultValue = "10") long size,
                                            @RequestParam(required = false) String supplierInfo,
                                            @RequestParam(required = false) String orderNo,
                                            @RequestParam(required = false) String productName,
                                            @RequestParam(required = false) String purchaseDate) {
        Page<PurchaseReturnDetailVO> page = new Page<>(current, size);
        PurchaseReturnDetailQueryDTO queryDTO = new PurchaseReturnDetailQueryDTO();
        queryDTO.setSupplierInfo(supplierInfo);
        queryDTO.setOrderNo(orderNo);
        queryDTO.setProductName(productName);
        queryDTO.setPurchaseDate(purchaseDate);
        Page<PurchaseReturnDetailVO> result = purchaseReturnDetailService.pageQuery(page, queryDTO);

        Map<String, Object> data = new HashMap<>();
        data.put("records", result.getRecords());
        data.put("total", result.getTotal());
        data.put("current", result.getCurrent());
        data.put("size", result.getSize());
        return Result.success(data);
    }
} 